package extend.org.compiere.hrm;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.logging.Level;

import org.compiere.model.X_hrm_set_tax;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

public class TaxRates {
	
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (TaxRates.class);
	
	public BigDecimal IPN = Env.ZERO;
	public BigDecimal OPV = Env.ZERO;
	public BigDecimal CNALOG = Env.ZERO;
	public BigDecimal COTCH = Env.ZERO;
	public BigDecimal MZP = Env.ZERO;
	public BigDecimal MRP = Env.ZERO;
	public BigDecimal MAXPENSION = Env.ZERO;
	public BigDecimal MINPENSION = Env.ZERO;
	public BigDecimal PENSIONBASE = Env.ZERO;
	
	/** */
	private Timestamp dateFrom;
	/** */

	public TaxRates(Timestamp dt){
		this.dateFrom = dt;
	    PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		String sql = "SELECT hrm_taxtype, rate FROM HRM_SET_TAX \n" +
					  "WHERE "+DB.TO_DATE(dateFrom, true) + " BETWEEN STARTDATE AND ENDDATE";			
		try
		{
			pstmt = DB.prepareStatement(sql,null);				
			rs = pstmt.executeQuery();	
			while(rs.next()) {
				// TYPE, value-Rate
				String sTaxType = rs.getString(1);
				if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_MZP))
					MZP=rs.getBigDecimal(2);
				else if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_OPV))
					OPV=rs.getBigDecimal(2);
				else if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_MRP))
					MRP=rs.getBigDecimal(2);
				else if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_IPN))
					IPN=rs.getBigDecimal(2);
				else if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_CNALOG))
					CNALOG=rs.getBigDecimal(2);
				else if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_COTCH))
					COTCH=rs.getBigDecimal(2);
				else if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_MAXPENSION))
					MAXPENSION=rs.getBigDecimal(2);
				else if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_MINPENSION))
					MINPENSION=rs.getBigDecimal(2);
				else if(sTaxType.equals(X_hrm_set_tax.HRM_TAXTYPE_PENSIONBASE))
					PENSIONBASE=rs.getBigDecimal(2);
			}	
		}
		catch (SQLException e)
		{
			s_log.log(Level.SEVERE, "HRM_SET_TAX", e);
		}
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}	
	}
	

}	
